package com.xuecheng.content.agent.hystrix;

import com.xuecheng.api.teaching.model.dto.CompanyDTO;
import com.xuecheng.api.teaching.model.dto.WorkDTO;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.hystrix.BaseAPIHystrix;
import com.xuecheng.common.hystrix.BaseFallbackFactory;
import com.xuecheng.content.agent.TeachingApiAgent;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created on 2021/04/05/19:53 周一
 *
 * @author Lantin
 */

@Component
public class WorkApiAgentFallbackFactory extends BaseFallbackFactory<
        BaseAPIHystrix<WorkDTO>,
        WorkApiAgentFallbackFactory.WorkApiAgentHystrix,
        WorkApiAgentFallbackFactory.DevWorkApiAgentHystrix> {

    /**
     * <p>
     * 生产环境降级方法类
     * </p>
     * 返回
     */
    public static class WorkApiAgentHystrix extends BaseAPIHystrix<WorkDTO> implements TeachingApiAgent {
        public WorkApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<WorkDTO> getByWorkId(Long workId) {
            return baseFailResult();
        }

        /**
         * 根据租户Id获取机构信息（机构时一种租户）
         *
         * @param tenantId
         * @return
         */
        @Override
        public CompanyDTO getCompInfoDetail(Long tenantId) {
            return null;
        }

        @Override
        public RestResponse modifyWorkInfo(Map<String, Object> params, Long workId) {
            return baseFailResult();
        }
    }

    /**
     * <p>
     * 开发环境降级方法类
     * </p>
     * 返回一个默认值
     */
    public static class DevWorkApiAgentHystrix extends BaseAPIHystrix<WorkDTO> implements TeachingApiAgent {

        public DevWorkApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<WorkDTO> getByWorkId(Long workId) {
            return RestResponse.success(new WorkDTO());
        }

        /**
         * 根据租户Id获取机构信息（机构时一种租户）
         *
         * @param tenantId
         * @return
         */
        @Override
        public CompanyDTO getCompInfoDetail(Long tenantId) {
            return null;
        }

        @Override
        public RestResponse modifyWorkInfo(Map<String, Object> params, Long workId) {
            return RestResponse.validfail(CommonErrorCode.E_100106);
        }
    }
}
